<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
 
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include_once($phpbb_root_path . 'common.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include_once($phpbb_root_path . 'sv_common.' . $phpEx);

// Basic parameter data
$mode		= request_var('mode', '');

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('stockvirtual');

$user_id 	= $user->data['user_id'];

// return message format: "num_of_follower, i_am_following,"
if ($mode == 'add')
{
	$followee_user_id		= (int)(request_var('followee_user_id', ''));
	
	$sql = 'SELECT * FROM sv_follow_list WHERE followee_user_id=' . $followee_user_id . ' AND follower_user_id=' . $user_id;
	$result = $db->sql_query_limit($sql, 1); 
	
	if ($db->sql_fetchrow($result) == false)
	{
		$sql = 'INSERT IGNORE INTO sv_follow_list SET follower_user_id=' . $user_id . ', followee_user_id=' . $followee_user_id;
    	$result	= $db->sql_query($sql); 
 	}
	
	// get number of followers.
	$sql2 = 'SELECT COUNT(DISTINCT follower_user_id) AS num FROM sv_follow_list WHERE followee_user_id=' . $followee_user_id;
	$result2 = $db->sql_query($sql2); 
	$row2 = $db->sql_fetchrow($result2);	
	$follower_num = $row2['num'];
		
    echo "$follower_num, 1," . 'followee_user_id:' . $followee_user_id . '  follower_user_id: ' . $user_id;
    
}
else if ($mode == 'remove')
{
	$followee_user_id		= (int)(request_var('followee_user_id', ''));
	
	$sql = 'DELETE FROM sv_follow_list WHERE follower_user_id=' . $user_id . ' AND followee_user_id=' . $followee_user_id;
    $result	= $db->sql_query($sql); 
    
    // get number of followers.
	$sql2 = 'SELECT COUNT(DISTINCT follower_user_id) AS num FROM sv_follow_list WHERE followee_user_id=' . $followee_user_id;
	$result2 = $db->sql_query($sql2); 
	$row2 = $db->sql_fetchrow($result2);	
	$follower_num = $row2['num'];
	
    echo "$follower_num, 0," . 'followee_user_id:' . $followee_user_id . '  follower_user_id: ' . $user_id;
}



display_forums('', $config['load_moderators']);

// include nav links.
include_nav_links();

// Assign index specific vars
$template->assign_vars(array(

	'FORUM_IMG'				=> $user->img('forum_read', 'NO_NEW_POSTS'),
	'FORUM_NEW_IMG'			=> $user->img('forum_unread', 'NEW_POSTS'),
	'FORUM_LOCKED_IMG'		=> $user->img('forum_read_locked', 'NO_NEW_POSTS_LOCKED'),
	'FORUM_NEW_LOCKED_IMG'	=> $user->img('forum_unread_locked', 'NO_NEW_POSTS_LOCKED'),

	'S_LOGIN_ACTION'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
	'S_DISPLAY_BIRTHDAY_LIST'	=> ($config['load_birthdays']) ? true : false,
	'U_MONEY'					=> number_format($money),
	'S_LIST'					=> $list,
	'S_HOLDING_STOCK_LIST'		=> $holding_stock_list,
	'U_QUERY_USERNAME'			=> get_username($query_user_id),
	'S_EQUITY_CHANGE_LIST'		=> $equity_change_list,
	
	'S_SHOW_QUERY_USERNAME_IN_HOLDING_STOCK_LIST'	=> true,
	
	'U_MARK_FORUMS'		=> ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;mark=forums') : '',
	'U_MCP'				=> ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=front', true, $user->session_id) : '',
	

	)
);

// Output page
//page_header($user->lang['SV_QUERY_USER']);
//$template->set_filenames(array(
//	'body' => 'query_user.html')
//);
//page_footer();

?>